import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('createRoom')
export class createRoom extends Component {
    public _gameNumbers;  //游戏局数
    public _isBanShuJieSan; //是否半数解散

    start() {
        this._gameNumbers = 10;         //默认10局
        this._isBanShuJieSan = false;   //默认全票解散
    }

    update(deltaTime: number) {
        
    }

    onColseBtnClicked(){
        this.node.active = false;
    }

    //创建按钮被点击触发的函数
    onCreateBtnClicked(){
        let data = {
            createUserID:globalThis._userInfo.user_id,  //是由那个用户创建的房间
            gameNumbers:this._gameNumbers,              //创建房间的游戏局数
            isBanShuJieSan:this._isBanShuJieSan         //是否为半数解散
        }
        //console.log(`创建房间的用户ID是${data.createUserID},局数为${data.gameNumbers},是否为半票解散${data.isBanShuJieSan}`);
        globalThis._hallClientMgr._sendMessage('create_room',data);
    }

    //当局数按钮被点击时触发的函数
    onGameNumbersBtnClicked(target,arg){
        console.log(arg);
        switch(arg){
            case '10':
                this._gameNumbers = 10;
                break;
            case '20':
                this._gameNumbers = 20;
                break;
            default:
                break;
        }
    }

    //是否全票解散按钮点击时触发的函数
    onIsQuanPiaoBtnClicked(){
        if(this._isBanShuJieSan){
            this._isBanShuJieSan = false;
        }else{
            this._isBanShuJieSan = true;
        }
    }
}

